package com.example.myuniversity;

import com.university.fragment.GradeFragment;
import com.university.fragment.MajorFragment;
import com.university.fragment.RegionFragment;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class SelectActivity extends Activity {
	private RadioButton radioMajor,radioGrade,radioRegion;
	private ImageView imageFinish;
	private TextView txtMajor,txtGrade,txtRegion,txtTitle;
	private View viewMajor1,viewMajor2,viewGrade1,viewGrade2,viewRegion1,viewRegion2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select);
		init();
	}
	private void init() {
		viewMajor1=findViewById(R.id.view_select_major1);
		viewMajor2=findViewById(R.id.view_select_major2);
		viewGrade1=findViewById(R.id.view_select_grade1);
		viewGrade2=findViewById(R.id.view_select_grade2);
		viewRegion1=findViewById(R.id.view_select_region1);
		viewRegion2=findViewById(R.id.view_select_region2);
		
		imageFinish=(ImageView) findViewById(R.id.image_major_finish);
		txtTitle=(TextView) findViewById(R.id.txt_select_title);
		txtMajor=(TextView) findViewById(R.id.txt_select_major);
		txtGrade=(TextView) findViewById(R.id.txt_select_grade);
		txtRegion=(TextView) findViewById(R.id.txt_select_region);
		
		txtMajor.setTextColor(getResources().getColor(R.color.color_blue));
		
		radioMajor=(RadioButton) findViewById(R.id.radio_select_major);
		radioMajor.setOnClickListener(new OnItemClick());
		radioGrade=(RadioButton) findViewById(R.id.radio_select_grade);
		radioGrade.setOnClickListener(new OnItemClick());
		radioRegion=(RadioButton) findViewById(R.id.radio_select_region);
		radioRegion.setOnClickListener(new OnItemClick());
		imageFinish.setOnClickListener(new OnItemClick());
		
		viewMajor1.setOnClickListener(new OnItemClick());
		viewMajor2.setOnClickListener(new OnItemClick());
		viewGrade1.setOnClickListener(new OnItemClick());
		viewGrade2.setOnClickListener(new OnItemClick());
		viewRegion1.setOnClickListener(new OnItemClick());
		viewRegion2.setOnClickListener(new OnItemClick());
		
		txtMajor.setOnClickListener(new OnItemClick());
		txtGrade.setOnClickListener(new OnItemClick());
		txtRegion.setOnClickListener(new OnItemClick());
		
		FragmentManager manager=getFragmentManager();
		FragmentTransaction tf=manager.beginTransaction();
		tf.add(R.id.layout_select_fragment, new MajorFragment());
		tf.commit();
	}
	class OnItemClick implements OnClickListener{
		@Override
		public void onClick(View v) {
			FragmentManager manager=getFragmentManager();
			FragmentTransaction tf=manager.beginTransaction();
			switch (v.getId()) {
			case R.id.radio_select_major:
			case R.id.txt_select_major:
			case R.id.view_select_major1:
			case R.id.view_select_major2:
				radioMajor.toggle();
				txtTitle.setText("专业查询");
				txtMajor.setTextColor(getResources().getColor(R.color.color_blue));
				txtGrade.setTextColor(getResources().getColor(R.color.color_black));
				txtRegion.setTextColor(getResources().getColor(R.color.color_black));
				tf.replace(R.id.layout_select_fragment, new MajorFragment()).commit();
				break;
			case R.id.radio_select_grade:
			case R.id.txt_select_grade:
			case R.id.view_select_grade1:
			case R.id.view_select_grade2:
				radioGrade.toggle();
				txtTitle.setText("成绩查询");
				txtMajor.setTextColor(getResources().getColor(R.color.color_black));
				txtGrade.setTextColor(getResources().getColor(R.color.color_blue));
				txtRegion.setTextColor(getResources().getColor(R.color.color_black));
				tf.replace(R.id.layout_select_fragment, new GradeFragment()).commit();
				break;
			case R.id.radio_select_region:
			case R.id.txt_select_region:
			case R.id.view_select_region1:
			case R.id.view_select_region2:
				radioRegion.toggle();
				txtTitle.setText("地区查询");
				txtMajor.setTextColor(getResources().getColor(R.color.color_black));
				txtGrade.setTextColor(getResources().getColor(R.color.color_black));
				txtRegion.setTextColor(getResources().getColor(R.color.color_blue));
				tf.replace(R.id.layout_select_fragment, new RegionFragment()).commit();
				break;
			case R.id.image_major_finish:
				finish();
				break;
			default:
				break;
			}
		}
	}
}
